package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 添加菜品
     * @param dish
     */
   /* @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user) " +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品的分页条件查询
     * @param dish
     * @return
     */
    Page<DishVO> selectByCondition(Dish dish);

    /**
     * 判断菜品 是否起售 批量判断
     * @param ids
     * @return
     */
    int countEnableByIds(List<Long> ids);

    /**
     * 批量删除
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据id查询菜品的所有信息
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);
/**
 * 修改菜品
 */
@AutoFill
    void update(Dish dish);

    /**
     * 根据分类查询起售中菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 起售和停售套餐
     * @param id
     * @return
     */
    @Select("select d.* from setmeal s,setmeal_dish sd,dish d " +
            "where  s.id=sd.setmeal_id and d.id=sd.dish_id and s.id=#{id}")
    List<DishVO> getBySetmealId(Long id);
}
